#define _CRT_SECURE_NO_WARNINGS 1
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
typedef struct ListNode S;
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {
    S* ps = (S*)malloc(sizeof(S));
    S* pr = ps;
    S* l1;
    S* l2;
    l1 = list1;
    l2 = list2;
    if (list1 == NULL)
    {
        return list2;
    }
    if (list2 == NULL)
    {
        return list1;
    }
    while (l1 && l2)
    {
        if (l1->val < l2->val)
        {
            ps->next = l1;
            l1 = l1->next;
        }
        else {
            ps->next = l2;
            l2 = l2->next;
        }
        ps = ps->next;
    }
    if (l1)
    {
        ps->next = l1;
    }
    if (l2)
    {
        ps->next = l2;
    }
    return pr->next;
}